package mock

import (
	// "fmt"
	"net/http"

	"mall/common/resultx"
	"mall/service/forum/api/internal/handler/util"
	"mall/service/forum/api/internal/logic/mock"
	"mall/service/forum/api/internal/svc"
	"mall/service/forum/api/internal/types"

	// "github.com/sirupsen/logrus"
	"github.com/zeromicro/go-zero/rest/httpx"
)

func SearchHandler(svcCtx *svc.ServiceContext) http.HandlerFunc {
	return func(w http.ResponseWriter, r *http.Request) {
		var req types.MockSearchReq
		if err := httpx.Parse(r, &req); err != nil {
			// httpx.ErrorCtx(r.Context(), w, err)
			resultx.ParamErrorResult(r, w, err)
			return
		}

		l := mock.NewSearchLogic(r.Context(), svcCtx)
		var headers []*types.Header
		resp, err := l.Search(&req, &headers)
		// logrus.Info(fmt.Sprintf("SearchHandler headers: %+v", headers))
		// if err != nil {
		// 	httpx.ErrorCtx(r.Context(), w, err)
		// } else {
		// 	httpx.OkJsonCtx(r.Context(), w, resp)
		// }
		w = util.SetHeaders(w, headers)
		resultx.HttpResult(r, w, resp, err)
	}
}
